package com.weirong.smartvault.backservice.entity_model;

import com.weirong.smartvault.backservice.util.common.ListTool;
import com.weirong.smartvault.common.tools.spring.context.SpringContextUtil;
import com.weirong.smartvault.dao.CashboxConfRepository;
import com.weirong.smartvault.entity.CashboxConf;
import com.weirong.smartvault.entity.CashboxUnit;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * 于2017/12/7由 KFEB4 创建 .
 */
public class CashboxUnitModel {
    private CashboxUnit cashboxUnit;
    private CashboxConfRepository cashboxConfRepository;
    public CashboxUnitModel(CashboxUnit cashboxUnit){

        this.cashboxUnit = cashboxUnit;
        this.cashboxConfRepository = SpringContextUtil.getBean(CashboxConfRepository.class);
    }
    public Integer getId(){
        return this.cashboxUnit.getId();
    }
    public String getName(){
        return  this.cashboxUnit.getName();
    }
    public String getDescription(){
        return cashboxUnit.getDescription();
    }
    public List<CashboxConfModel> getConfs() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        List<CashboxConf> cashboxConfs= cashboxConfRepository.findAllByUnitNo(cashboxUnit.getNo());
        return ListTool.cast(cashboxConfs,CashboxConfModel.class) ;
    }
    public Integer getNo(){
        return cashboxUnit.getNo();
    }
}
